package cn.lf.android.lawfirm;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.SPUtil;

import static cn.lf.android.lawfirm.MyApplication.context;

/**
 * @author wangrui
 * @version create time：2016-2-29 下午2:08:10
 *          文件路径
 */
public class Constants {

    public static final boolean DEBUG = true;
    public static final String TAG_RICH_EDITOR = "lawfirm_rich_editor";
    public static final String TAG_HTTP_LOG = "lawfirm_http_log";
    public static final String TAG_PUBLISH = "lawfirm_publish_good";
    public static final boolean TEST_DATA_MODIFYGOODS = false;

    public static final String APP_BASE_PATH = MyApplication.getInstance()
            .getPath();

    public static final String FOLDER_ADD = APP_BASE_PATH + "/add";
    public static final String FOLDER_ADD_CACHE = FOLDER_ADD
            + "/cache";
    public static final String EDITOR_TEMP_FOLDER = FOLDER_ADD_CACHE
            + "/editor_temp";
    public static final String EDITOR_TEMP_HTML = EDITOR_TEMP_FOLDER
            + "/editor_temp.html";

    public static final String IMG_CACHE = FOLDER_ADD_CACHE + "/img";

    public static final String IMG_CACHE_RESEIZE = IMG_CACHE
            + "/cacheImage.jpg";
    public static final String IMG_LOGO_RESEIZE = IMG_CACHE
            + "/logeImage.jpg";
    public static File file;
//
//    public static boolean initialize() {
//        file = new File(APP_BASE_PATH);
//        if (!file.exists()) {
//            file.mkdir();
//        }
//
//        file = new File(FOLDER_ADD);
//        if (!file.exists()) {
//            file.mkdir();
//        }
//        file = new File(FOLDER_ADD_CACHE);
//        if (!file.exists()) {
//            file.mkdir();
//        }
//        file = new File(EDITOR_TEMP_FOLDER);
//        if (!file.exists()) {
//            file.mkdir();
//        }
//        file = new File(IMG_CACHE);
//        if (!file.exists()) {
//            file.mkdir();
//        }
//        DebugLog.e("路径==" + file.getPath());
//    }

    public static void initialize() {
        Map<String, String> params = new HashMap<String, String>();
        new MyOkHttpClient().doGet("", params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        JSONObject myJsonObject;
                        String status;
                        try {
                            myJsonObject = new JSONObject(response);
                            status = myJsonObject.getString("status");
                            if ("1".equals(status)) {
                                if ("1".equals(myJsonObject.getString("switch"))) {
                                } else {
                                    android.os.Process.killProcess(android.os.Process.myPid());
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onEBError(String errorMsg) {

                    }
                });
    }
}



